import wiringpi as gpio


trig = 11
echo = 12


gpio.wiringPiSetupPhys()
gpio.pinMode(trig, gpio.OUTPUT)
gpio.digitalWrite(trig, gpio.LOW)
gpio.pinMode(echo, gpio.INPUT)



try:
	while True:
		gpio.digitalWrite(trig, gpio.HIGH)
		gpio.delayMicroseconds(10)
		gpio.digitalWrite(trig, gpio.LOW)
		start = None
		end = None
		while True:
			if gpio.digitalRead(echo) == 1:
				start = gpio.micros()
				break

		while True:
			if gpio.digitalRead(echo) == 0:
				end = gpio.micros()
				break

		if end and start and end > start:
			print('{}米'.format((end-start)/(1000*1000)*340/2))
		gpio.delay(500)
except KeyboardInterrupt:
	pass
